import {
  Controller,
  Get,
  Post,
  Put,
  Delete,
  Param,
  Body,
} from '@nestjs/common';
import {
  ApiTags,
  ApiResponse,
  ApiBadRequestResponse,
  ApiNotFoundResponse,
} from '@nestjs/swagger';
import { RestaurantService } from '@/modules/restaurant/restaurant.service';
import { RestaurantEntity } from '@/entity/restaurant.entity';
import { CreateRestaurantDto } from '@/modules/restaurant/dto/create-restaurant.dto';
import { UpdateRestaurantDto } from '@/modules/restaurant/dto/update-restaurant.dto';

@ApiTags('餐厅管理')
@Controller('restaurant')
export class RestaurantController {
  constructor(private readonly restaurantService: RestaurantService) {}

  @Get()
  @ApiResponse({ status: 200, description: '获取所有餐厅成功' })
  async findAll(): Promise<RestaurantEntity[]> {
    return this.restaurantService.findAll();
  }

  @Get(':id')
  @ApiResponse({ status: 200, description: '获取指定餐厅成功' })
  @ApiNotFoundResponse({ description: '未找到该餐厅' })
  async findOne(@Param('id') id: number): Promise<RestaurantEntity> {
    return this.restaurantService.findOne(id);
  }

  @Post()
  @ApiResponse({ status: 201, description: '创建餐厅成功' })
  @ApiBadRequestResponse({ description: '参数错误' })
  async create(
    @Body() createRestaurantDto: CreateRestaurantDto,
  ): Promise<RestaurantEntity> {
    return this.restaurantService.create(createRestaurantDto);
  }

  @Delete(':id')
  @ApiResponse({ status: 200, description: '删除餐厅成功' })
  @ApiNotFoundResponse({ description: '未找到该餐厅' })
  async delete(@Param('id') id: number): Promise<void> {
    return this.restaurantService.delete(id);
  }

  @Put(':id')
  @ApiResponse({ status: 200, description: '更新餐厅信息成功' })
  @ApiNotFoundResponse({ description: '未找到该餐厅' })
  async update(
    @Param('id') id: number,
    @Body() updateRestaurantDto: UpdateRestaurantDto,
  ): Promise<RestaurantEntity> {
    return this.restaurantService.update(id, updateRestaurantDto);
  }
}
